package com.yoyo.svgdemo.fragment;/**
 * Created by liumin on 2015-9-1.
 */


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.io.Serializable;


/**
 * User: Missa
 * Date: 2015-09-01
 * Time: 15:30
 * Description:
 */
public abstract class BaseFragment extends Fragment implements Serializable {
    private View mRootView;

//    public LayoutInflater mInflater;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//        mInflater = LayoutInflater.from(getActivity());
        if(mRootView == null){
            mRootView = initiateView(inflater, container);
            System.out.println("BaseFragment ============ oncreateView ============ mRootView = null");
        }
        return mRootView;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        initData();
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        if (mRootView != null) {
            System.out.println("BaseFragment ============ onDestroyView ============ mRootView != null");
            ((ViewGroup) mRootView.getParent()).removeView(mRootView);
        }
    }

    public abstract View initiateView(LayoutInflater inflater, ViewGroup container);

    public abstract void initData();

}
